<?php
class Leksem {

	private $_model = '';
	
	public $id = '';
	
	public $userId = '';
	
	public $name = '';

    public $context = '';
	
	public $value = '';
	
	public $websiteId = '';
	
	public $translated = false;

	
	public function __construct($leksemId = null) {
		$this->_model = new LeksemObjModel();
		if($leksemId) {
			$leksemData = $this->_model->getLeksById($leksemId);
			if(!empty ($leksemData)) {
				foreach ($leksemData as $data) {
					$this->id = $data->id;
					$this->userId = $data->id_user;
					$this->name = $data->name;
					$this->context = $data->context;
					$this->translated = $data->translated;
					$this->value = $data->value;
					$this->websiteId = $data->id_website;
				}
			}
		}
	}
	
	public function save() {
		if(empty($this->id)) {
			$this->_model->save($this);
		}
		else {
			$this->_model->update($this);
		}
	}
	
	public function delete() {
		$this->_model->delete($this->id);
	}
	
	public function markTranslated(){
		$this->_model->markTranslated($this->id);
	}
	
	public function markUntranslated(){}

	public function isTranslated() {
		return (bool)$this->translated;
	}

	public function setTranslated($translatedFlag) {
		$this->translated = $translatedFlag;
	}
    public function isTranslatedInto($dictId) {
        $result = $this->_model->getTranslatedInto($this->id, $dictId);
        if($result) {
            return 1;
        }
        return 0;
    }
}